<template>
  <!--菜单 -->
  <div
    class="sky-menu-ws"
    :style="{
      backgroundColor: backgroundColor,
      justifyContent: justifyContent,
    }"
  >
    <slot name="logo"></slot>
    <ul
      :default-active="defaultActive"
      class="sky-menu"
      :background-color="backgroundColor"
      :text-color="textColor"
    >
      <li
        class="sky-menu-item"
        :style="{
          color: defaultActive === index ? activeTextColor : textColor,
        }"
        v-for="(menu, index) in menuList"
        :key="index"
      >
        <span @click="selectMenu(menu)">{{ menu.name }}</span>
        <div
          v-if="menu.children"
          class="second-menu"
          :style="{ color: textColor, backgroundColor: backgroundColor }"
        >
          <span
            @click="selectMenu(m, menu)"
            class="sky-menu-item"
            v-for="m in menu.children"
            :key="m.name"
            >{{ m.name }}</span
          >
        </div>
      </li>
    </ul>
    <slot name="tel"></slot>
  </div>
</template>
<script>
export default {
  name: "skyMenu",
  props: {
    menuList: {
      type: Array,
      default: () => [],
    },
    backgroundColor: {
      type: String,
      default: "#333",
    },
    textColor: {
      type: String,
      default: "#fff",
    },
    activeTextColor: {
      type: String,
      default: "#ffd04b",
    },
    defaultActive: {
      type: Number,
      default: 0,
    },
    justifyContent: {
      type: String,
      default: "space-between",
    },
  },
  data() {
    return {};
  },
  methods: {
    selectMenu(cur, parent = null) {
      console.log(cur, parent);
      if (!cur.children) {
        this.$router.push({ path: cur.path });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.sky-menu-ws {
  position: fixed;
  z-index: 10;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  align-items: center;
  padding: 10px;
}
.sky-menu {
  justify-content: flex-end;
  font-size: 18px;
  padding: 19px 10px;
  margin: 0;
  cursor: pointer;
  .sky-menu-item {
    position: relative;
    display: inline-block;
    min-width: 120px;
    text-align: center;
    list-style: none;
    .second-menu {
      position: absolute;
      padding: 10px 0;
      display: none;
      background-color: #fff;
      border-radius: 8px;
      // margin-top: 12px;
      line-height: 44px;
    }
    &:hover {
      text-decoration: underline;
    }
    &:hover .second-menu {
      display: block;
    }
  }
}
</style>